﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MasterForms;
using BahdlClassLib;
using BusinessLayer;
namespace PayRoll
{
    public partial class StartMain : Form
    {
        private int intEmployeeID = 0;
        private bool bIsPasswordChanged = false;

        public StartMain()
        {
            InitializeComponent();

        }

        public StartMain(int intSetEmployeeID, Boolean blPasswordChangeStatus)
        {
            InitializeComponent();                       
            intEmployeeID = intSetEmployeeID;
            bIsPasswordChanged = blPasswordChangeStatus;
            ClsEmployee emp = new ClsEmployee();
            emp.GetEmployee(intSetEmployeeID);


            //Check for user Role
            //hide menus based on role
            if (emp.Role == "EMPLOYEE")
            {
                menuStrip.Items["masterMenu"].Visible = false;
                menuStrip.Items["toolStripSalary"].Visible = false;
                toolStrip.Items["createUserToolStripButton"].Visible = false;
                toolStrip.Items["CashiertoolStripButton1"].Visible = false;
                toolStrip.Items["reporttoolStripButton1"].Visible = false;

                foreach (ToolStripMenuItem tsmi in menuStrip.Items)
                {
                    tsmi.DropDownItems[1].Visible = false;
                }
            }

            this.statusStrip.Items[0].Text = "WELCOME " + emp.FullName + " (" + emp.Role + ")";
        }


        private void Designation_Click(object sender, EventArgs e)
        {
            Designation designation = new Designation();
            designation.MdiParent = this;
            designation.Show();

        }

        private void StartMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.ExitThread();
            Application.Exit();
        }

        private void closeAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();                
            }
        }

        private void tileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void employmentTypeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EmploymentType EmploymentType = new EmploymentType();
            EmploymentType.MdiParent = this;
            EmploymentType.Show();

        }

        private void leaveTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FinancialYear frmFinancialYear = new FinancialYear();
            frmFinancialYear.MdiParent = this;
            frmFinancialYear.Show();


        }

        private void employmentStatusTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EmploymentStatusType frmEmploymentStatusType = new EmploymentStatusType();
            frmEmploymentStatusType.MdiParent = this;
            frmEmploymentStatusType.Show();

        }

        private void salaryHeadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SalaryHead frmSalaryHead = new SalaryHead();
            frmSalaryHead.MdiParent = this;
            frmSalaryHead.Show();


        }

        private void roleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RoleMaster frmRoleMaster = new RoleMaster();
            frmRoleMaster.MdiParent = this;
            frmRoleMaster.Show();

        }

        private void workingHourToolStripMenuItem_Click(object sender, EventArgs e)
        {

            WorkingHours frmWorkingHours = new WorkingHours();
            frmWorkingHours.MdiParent = this;
            frmWorkingHours.Show();

        }

        private void employeeMasterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EmployeeJoining frmEmployeeJoining = new EmployeeJoining();
            frmEmployeeJoining.MdiParent = this;
            frmEmployeeJoining.Show();
        }

        private void holidaysToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Holidays frmHolidays = new Holidays();
            frmHolidays.MdiParent = this;
            frmHolidays.Show();
        }

        private void holidaysMasterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HolidaysMaster frmHolidaysMaster = new HolidaysMaster();
            frmHolidaysMaster.MdiParent = this;
            frmHolidaysMaster.Show();
        }

        private void departmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Department frmHolidaysMaster = new Department();
            frmHolidaysMaster.MdiParent = this;
            frmHolidaysMaster.Show();
        }

        private void attendanceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.groupBox1 .Visible = false;
            this.groupBox2.Visible = false;
            Attendance frmAttendance = new Attendance();
            frmAttendance.MdiParent = this;           
            frmAttendance.Show();
        }

        private void companyInfoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CompanyInfo frmCompanyInfo = new CompanyInfo();
            frmCompanyInfo.MdiParent = this;
            frmCompanyInfo.Show();
        }

        private void manageAttendanceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.groupBox1.Visible = false;
            this.groupBox2.Visible = false;

            ManageAttendance frmManageAttendance = new ManageAttendance();
            frmManageAttendance.MdiParent = this;
            frmManageAttendance.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.ExitThread();
            Application.Exit();
        }

        private void StartMain_Load(object sender, EventArgs e)
        {
            if (!bIsPasswordChanged)
            {
                ChangePassword frmChangePassword = new ChangePassword(intEmployeeID, false);
                frmChangePassword.ShowDialog();
            }

            else
            {
                CLsBirthday objBirthady = new CLsBirthday();
                List<ClsEmployee> lstEmployees = new List<ClsEmployee>();
                lstEmployees = objBirthady.GetTodayBirthdays();
               
                int x = 3;
                int y = 24;
                if (lstEmployees.Count > 0)
                {  
                    foreach (ClsEmployee item in lstEmployees)
                    { 
                        Label lblDynamic = new Label();
                        lblDynamic.ForeColor = Color.Snow;
                        lblDynamic.Font = new Font("Times New Roman", 9, FontStyle.Bold);
                        lblDynamic.Location = new Point(x, y); 
                        lblDynamic.Text = item.FirstName.ToString() + " " + item.MiddleName.ToString() + " " + item.LastName.ToString();
                        groupBox1.Controls.Add(lblDynamic);                       
                        y += 25;

                    }
                }

                else
                {

                    Label lblDynamic = new Label();
                    lblDynamic.Location = new Point(x, y);
                    lblDynamic.Font = new Font("Times New Roman", 9, FontStyle.Bold);
                    lblDynamic.ForeColor = Color.Coral;
                    lblDynamic.Text = "!! No Birthday !!";                    
                    groupBox1.Controls.Add(lblDynamic);
                    y += 25;
                    
                }
                
                

                x = 3;
                y = 24;
                lstEmployees = objBirthady.GetBirthdays(DateTime.Now.Month);
                if (lstEmployees.Count == 0)
                {
                    Label lblDynamicUpcoming = new Label();                 
                    lblDynamicUpcoming.Location = new Point(x, y);
                    lblDynamicUpcoming.Font = new Font("Times New Roman", 9, FontStyle.Bold);
                    lblDynamicUpcoming.ForeColor = Color.Coral;
                    lblDynamicUpcoming.Text = "!! No Birthday !!";
                    groupBox2.Controls.Add(lblDynamicUpcoming);
                    y += 60;
               
                }
                else
                {
                    bool found = false;
                    foreach (ClsEmployee item in lstEmployees)
                    {
                        if (lstEmployees.Count > 0)
                        {
                            if (item.DOB.Value.Day != DateTime.Now.Day && item.DOB.Value.Day > DateTime.Now.Day)
                            {
                                
                                Label lblDynamicUpcoming = new Label();
                                lblDynamicUpcoming.Location = new Point(x, y);
                                lblDynamicUpcoming.Font = new Font("Times New Roman", 9, FontStyle.Bold);
                                lblDynamicUpcoming.ForeColor = Color.Snow;
                                lblDynamicUpcoming.Text = item.FirstName.ToString() + " " + item.MiddleName.ToString() + " " + item.LastName.ToString();                                
                                Label lblDynamicUpcomingYear = new Label();                             
                                x += 150;
                                string steDATE = item.DOB.Value.Day.ToString();
                                lblDynamicUpcomingYear.Location = new Point(x, y);
                                lblDynamicUpcomingYear.ForeColor = Color.Snow;
                                lblDynamicUpcomingYear.Font = new Font("Times New Roman", 9, FontStyle.Bold);
                                lblDynamicUpcomingYear.Text = steDATE + " " + item.DOB.Value.ToString("MMMM") + "    ";
                                groupBox2.Controls.Add(lblDynamicUpcoming);
                                groupBox2.Controls.Add(lblDynamicUpcomingYear);
                                y += 25;
                                x -= 150;
                                found = true;
                            }
                        }
                    }
                    if (!found)
                    {
                        Label lblDynamicUpcoming = new Label();
                        lblDynamicUpcoming.Location = new Point(x, y);
                        lblDynamicUpcoming.Font = new Font("Times New Roman", 9, FontStyle.Bold);
                        lblDynamicUpcoming.ForeColor = Color.Coral;
                        lblDynamicUpcoming.Text = "!! No Birthday !!";
                        groupBox2.Controls.Add(lblDynamicUpcoming);
                        y += 60;
                    }
                }
               

            }
        }


        private void toolSalaryProcess_Click(object sender, EventArgs e)
        {
            SalaryProcess frmSalaryProcess = new SalaryProcess();
            frmSalaryProcess.MdiParent = this;
            frmSalaryProcess.Show();
        }

        private void toolSalaryGeneration_Click(object sender, EventArgs e)
        {
            this.groupBox1.Visible = false;
            this.groupBox2.Visible = false;

            SalaryGeneration frmSalaryGeneration = new SalaryGeneration();
            frmSalaryGeneration.MdiParent = this;
            frmSalaryGeneration.Show();
        }

        private void AttendanceToolStripButton_Click(object sender, EventArgs e)
        {
            Attendance frmAttendance = new Attendance();
            frmAttendance.MdiParent = this;
            frmAttendance.Show();
        }

        private void CashiertoolStripButton1_Click(object sender, EventArgs e)
        {
            SalaryGeneration frmSalaryGeneration = new SalaryGeneration();
            frmSalaryGeneration.MdiParent = this;
            frmSalaryGeneration.Show();
        }

        private void changePasswordToolStripButton_Click(object sender, EventArgs e)
        {

            ChangePassword frmChangePassword = new ChangePassword(intEmployeeID, true);
            frmChangePassword.MdiParent = this;
            frmChangePassword.Show();


        }

        private void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Report frmChangePassword = new Report();
            frmChangePassword.LoadSalaryReport(1, 1);
            frmChangePassword.Show();
        }

        private void StartMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (UIFunction.SureToExit(" the Application ? ") == true)
            {
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;

            }
        }

        private void createUserToolStripButton_Click(object sender, EventArgs e)
        {
            EmployeeJoining frmEmployeeJoining = new EmployeeJoining();
            frmEmployeeJoining.MdiParent = this;
            frmEmployeeJoining.Show();

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            Application.Exit();
        }

        private void financialYearReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FinancialYearReport frmFinancialYearReport = new FinancialYearReport();
            frmFinancialYearReport.MdiParent = this;
            frmFinancialYearReport.Show();
        }

        private void myProfileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EmployeeJoining frmEmployeeJoining = new EmployeeJoining(intEmployeeID, true);
            frmEmployeeJoining.MdiParent = this;
            frmEmployeeJoining.Show();
        }

        private void toolStripMyProfile_Click(object sender, EventArgs e)
        {
            EmployeeJoining frmEmployeeJoining = new EmployeeJoining(intEmployeeID, true);
            frmEmployeeJoining.MdiParent = this;
            frmEmployeeJoining.Show();
        }

        private void reporttoolStripButton1_Click(object sender, EventArgs e)
        {
            FinancialYearReport frmFinancialYearReport = new FinancialYearReport();
            frmFinancialYearReport.MdiParent = this;
            frmFinancialYearReport.Show();
        }
        

    }
}
